home *** CD-ROM | disk | FTP | other *** search
- Path: engnews2.Eng.Sun.COM!usenet
- From: ball@Eng.Sun.COM (Mike Ball)
- Newsgroups: comp.lang.c++
- Subject: Re: "Pure virtual function called" error
- Date: 11 Apr 1996 15:15:28 GMT
- Organization: Sun Microsystems Inc.
- Message-ID: <4kj7mg$q59@engnews2.Eng.Sun.COM>
- References: <Pine.OSF.3.91.960411112749.11275A-100000@bud.cc.swin.edu.au>
- Reply-To: ball@Eng.Sun.COM
- NNTP-Posting-Host: cygany.eng.sun.com
-
- In article 100000@bud.cc.swin.edu.au, John Joseph Newbigin <079519@bud.cc.swin.edu.au> writes:
- > On Wed, 10 Apr 1996, Oliver Peck wrote:
- >
- > > I am using V4.0.1 of the Sparcworks C++ compiler.
- > >
- > > A program is occasionally crashing with the message:-
- > >
- > > "**** Pure virtual function called"
- > >
- > > Does anyone know what this may mean?
- > >
- >
- > If you have a class that inherits another class with a pure virtual
- > function, you MUST write this function for your class because it is only
- > a deffition in the class you are inhereting. I have never used this but
- > I assume borland C++ would not alow this to compile but I don't know
- > about other compilers. The compiler may be providing a stub. with this
- > error to alow your program to compile. To overcome this you will have
- > to write the function for one of the classes(or both). .....I think:)
- >
-
- Well, if I must, I must....
-
- This is about 95% nonsense. It does indeed mean that you are trying to call
- a pure function. You will get this error whether or not you provide a definition
- for the function. The class for which this occurs, being an abstract class,
- must be a base class of some entire class which overrides and defines this
- virtual function. If this isn't true, the program won't compile. During
- construction (destruction) of the entire class, the code must ensure that
- when a base class is being constructed (destructed) the polymorphic behavior
- of the class is the same as the particular base class being handled. If one
- of these constructors (destructors) calls, directly or indirectly, a pure
- virtual function, you will get this message.
-
- You can also get the message by calling a virtual function on a deleted class,
- as another post points out. Of course that is undefined behavior, so you
- could get ANY message in that situation. Despite the claim that this is the
- most common cause, I've never seen it in real code. I think it depends on the
- programming disciplines being applied.
-
- ---
- Michael Ball
- SunSoft Development Products
-
-
-